<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
  Class: Rcurse::Engine
  
    &mdash; Documentation by YARD 0.8.7.4
  
</title>

  <link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />

  <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />

  <link rel="stylesheet" href="../css/docs.css" type="text/css" charset="utf-8" />

<script type="text/javascript" charset="utf-8">
  hasFrames = window.top.frames.main ? true : false;
  relpath = '../';
  framesUrl = "../frames.html#!Rcurse/Engine.html";
</script>


  <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>

  <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>


  </head>
  <body>
    <div id="header">
      <div id="menu">
  
    <a href="../_index.html">Index (E)</a> &raquo;
    <span class='title'><span class='object_link'><a href="../Rcurse.html" title="Rcurse (module)">Rcurse</a></span></span>
     &raquo; 
    <span class="title">Engine</span>
  

  <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
</div>

      <div id="search">
  
    <a class="full_list_link" id="class_list_link"
        href="../class_list.html">
      Class List
    </a>
  
    <a class="full_list_link" id="method_list_link"
        href="../method_list.html">
      Method List
    </a>
  
    <a class="full_list_link" id="file_list_link"
        href="../file_list.html">
      File List
    </a>
  
</div>
      <div class="clear"></div>
    </div>

    <iframe id="search_frame"></iframe>

    <div id="content"><h1>Class: Rcurse::Engine
  
  
  
</h1>

<dl class="box">
  
    <dt class="r1">Inherits:</dt>
    <dd class="r1">
      <span class="inheritName">Object</span>
      
        <ul class="fullTree">
          <li>Object</li>
          
            <li class="next">Rcurse::Engine</li>
          
        </ul>
        <a href="#" class="inheritanceTree">show all</a>
      
      </dd>
    
  
  
    
  
    
  
  
  
    <dt class="r2 last">Defined in:</dt>
    <dd class="r2 last">lib/rcurse/engine.rb</dd>
  
</dl>
<div class="clear"></div>

<h2>Overview</h2><div class="docstring">
  <div class="discussion">
    
<p>The Rcurse engine</p>


  </div>
</div>
<div class="tags">
  

</div>






  
    <h2>
      Class Method Summary
      <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
    </h2>

    <ul class="summary">
      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#render-class_method" title="render (class method)">+ (String) <strong>render</strong>(content, context = Context.new) </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>Render a template.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#render_file-class_method" title="render_file (class method)">+ (String) <strong>render_file</strong>(filename, out_filename = nil, context = Context.new) </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>
<p>Render a template file, optionally writing output to another file.</p>
</div></span>
  
</li>

      
    </ul>
  



  <div id="class_method_details" class="method_details_list">
    <h2>Class Method Details</h2>

    
      <div class="method_details first">
  <h3 class="signature first" id="render-class_method">
  
    + (<tt>String</tt>) <strong>render</strong>(content, context = Context.new) 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>Render a template</p>


  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>content</span>
      
      
        <span class='type'>(<tt>String</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>A String containing the Rcurse template</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>context</span>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="Context.html" title="Rcurse::Context (class)">Rcurse::Context</a></span></tt>)</span>
      
      
        <em class="default">(defaults to: <tt>Context.new</tt>)</em>
      
      
        &mdash;
        <div class='inline'>
<p>a context for the template</p>
</div>
      
    </li>
  
</ul>

<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>String</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>The rendered template</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/rcurse/engine.rb', line 11</span>

<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_render'>render</span> <span class='id identifier rubyid_content'>content</span><span class='comma'>,</span> <span class='id identifier rubyid_context'>context</span> <span class='op'>=</span> <span class='const'>Context</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>

    <span class='comment'># find Rcurse calls in template
</span>    <span class='comment'># Regex explaination - http://goo.gl/vpKPeZ
</span>    <span class='id identifier rubyid_content'>content</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>({{|{%=|{%)(.+?)[}|%]}</span><span class='regexp_end'>/</span></span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_match'>match</span><span class='op'>|</span>
        <span class='comment'># return unaltered if nothing is done
</span>        <span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='id identifier rubyid_match'>match</span>

        <span class='id identifier rubyid_type'>type</span> <span class='op'>=</span> <span class='backref'>$1</span>
        <span class='id identifier rubyid_content'>content</span> <span class='op'>=</span> <span class='backref'>$2</span>

        <span class='comment'># determine what to do
</span>        <span class='comment'># helper calls start with {{
</span>        <span class='comment'># silent eval calls start with {%
</span>        <span class='comment'># eval calls start with {%=
</span>        <span class='kw'>case</span> <span class='id identifier rubyid_type'>type</span>
        <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>{{</span><span class='tstring_end'>&quot;</span></span>
            <span class='id identifier rubyid_content_parts'>content_parts</span> <span class='op'>=</span> <span class='id identifier rubyid_content'>content</span><span class='period'>.</span><span class='id identifier rubyid_chomp'>chomp</span><span class='period'>.</span><span class='id identifier rubyid_split'>split</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'> </span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
            <span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='id identifier rubyid_content_parts'>content_parts</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span>

            <span class='comment'># omit the first element
</span>            <span class='id identifier rubyid_args'>args</span> <span class='op'>=</span> <span class='id identifier rubyid_content_parts'>content_parts</span><span class='lbracket'>[</span><span class='int'>1</span><span class='op'>..</span><span class='op'>-</span><span class='int'>1</span><span class='rbracket'>]</span>

            <span class='comment'># check if helper exists
</span>            <span class='kw'>if</span> <span class='const'>Rcurse</span><span class='op'>::</span><span class='id identifier rubyid_helpers'>helpers</span><span class='lbracket'>[</span><span class='id identifier rubyid_name'>name</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span> <span class='const'>Rcurse</span><span class='op'>::</span><span class='const'>Helper</span> <span class='kw'>then</span>
                <span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='const'>Rcurse</span><span class='op'>::</span><span class='id identifier rubyid_helpers'>helpers</span><span class='lbracket'>[</span><span class='id identifier rubyid_name'>name</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_callback'>callback</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='id identifier rubyid_context'>context</span><span class='rparen'>)</span>
            <span class='kw'>end</span>
        <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>{%</span><span class='tstring_end'>&quot;</span></span>
            <span class='comment'># evaluate code inside {% %}
</span>            <span class='id identifier rubyid_context'>context</span><span class='period'>.</span><span class='id identifier rubyid_eval'>eval</span><span class='lparen'>(</span><span class='id identifier rubyid_content'>content</span><span class='rparen'>)</span>

            <span class='comment'># remove code from template
</span>            <span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_end'>&quot;</span></span>
        <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>{%=</span><span class='tstring_end'>&quot;</span></span>
            <span class='comment'># evaluate code and write result to template
</span>            <span class='id identifier rubyid_result'>result</span> <span class='op'>=</span> <span class='id identifier rubyid_context'>context</span><span class='period'>.</span><span class='id identifier rubyid_eval'>eval</span><span class='lparen'>(</span><span class='id identifier rubyid_content'>content</span><span class='rparen'>)</span>
        <span class='kw'>end</span>

        <span class='comment'># return the result. replacing the Rcurse call
</span>        <span class='id identifier rubyid_result'>result</span>
    <span class='kw'>end</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="render_file-class_method">
  
    + (<tt>String</tt>) <strong>render_file</strong>(filename, out_filename = nil, context = Context.new) 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    
<p>Render a template file, optionally writing output to another file</p>


  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>filename</span>
      
      
        <span class='type'>(<tt>String</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>A String containing the Rcurse template</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>out_filename</span>
      
      
        <span class='type'>(<tt>String</tt>)</span>
      
      
        <em class="default">(defaults to: <tt>nil</tt>)</em>
      
      
        &mdash;
        <div class='inline'>
<p>Optional, file to write output to</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>context</span>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="Context.html" title="Rcurse::Context (class)">Rcurse::Context</a></span></tt>)</span>
      
      
        <em class="default">(defaults to: <tt>Context.new</tt>)</em>
      
      
        &mdash;
        <div class='inline'>
<p>a context for the template</p>
</div>
      
    </li>
  
</ul>

<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>String</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>
<p>The rendered template</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


60
61
62
63
64
65
66
67
68
69</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/rcurse/engine.rb', line 60</span>

<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_render_file'>render_file</span> <span class='id identifier rubyid_filename'>filename</span><span class='comma'>,</span> <span class='id identifier rubyid_out_filename'>out_filename</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_context'>context</span> <span class='op'>=</span> <span class='const'>Context</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
    <span class='id identifier rubyid_content'>content</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span><span class='lparen'>(</span><span class='id identifier rubyid_filename'>filename</span><span class='rparen'>)</span>
    <span class='id identifier rubyid_context'>context</span><span class='period'>.</span><span class='id identifier rubyid_path'>path</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_dirname'>dirname</span><span class='lparen'>(</span><span class='id identifier rubyid_filename'>filename</span><span class='rparen'>)</span>
    <span class='id identifier rubyid_rendered_content'>rendered_content</span> <span class='op'>=</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_render'>render</span><span class='lparen'>(</span><span class='id identifier rubyid_content'>content</span><span class='comma'>,</span> <span class='id identifier rubyid_context'>context</span><span class='rparen'>)</span>

    <span class='comment'># write rendered content to output file if specified
</span>    <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_open'>open</span><span class='lparen'>(</span><span class='id identifier rubyid_out_filename'>out_filename</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>w+</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_file'>file</span><span class='op'>|</span> <span class='id identifier rubyid_file'>file</span><span class='period'>.</span><span class='id identifier rubyid_write'>write</span><span class='lparen'>(</span><span class='id identifier rubyid_rendered_content'>rendered_content</span><span class='rparen'>)</span> <span class='rbrace'>}</span> <span class='kw'>if</span> <span class='id identifier rubyid_out_filename'>out_filename</span>

    <span class='kw'>return</span> <span class='id identifier rubyid_rendered_content'>rendered_content</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
  </div>

</div>

    
  </body>
</html>